<?php

include_once ("./functions_for_filter.php");
$db_name = "filter_words";
$dbcnx = connect_db($db_name);
//$index = 6;

	for ($index = 1; $index <= 6; $index++)
	{
		$tab_name = "level" . $index . "_words_" . "irr";
		//$tab_name = "level" . $index . "_words_" . "prototype";
		$file_name = "irregular_verb" . $index;
		$sql = "select count(*) from $tab_name;";
		$result = mysql_query ($sql, $dbcnx);
		$row = mysql_fetch_row ($result);
		$amount = $row[0];
		echo $amount . "\n";

		if ($amount ==0 )
		{
			//$handle = fopen("../../string/words_statistics/words_levels/" . $index . ".txt", "r");
			$handle = fopen("../../string/words_statistics/db_operations/" . $file_name, "r");

			if ($handle) 
			{
				while (!feof($handle)) 
				{
					$buffer = trim(fgetss($handle, 4096));
					if ( "#" != substr ($buffer, 0, 1) && !empty($buffer) )
					{
						$sql = "INSERT INTO " . $tab_name . " (word) VALUES(\"" . $buffer . "\");";
						$res = mysql_query($sql, $dbcnx);
						//echo $buffer;
					}
				}
				fclose($handle);
			}
			echo "stored " . $file_name . " to " . $tab_name . "\n";
		}
	}

mysql_close($dbcnx);

?>
